#[cfg(windows)]
fn main() {
    use serial_cmd::utils::{logger, session::Session};
    use serialport::{DataBits, FlowControl, Parity, StopBits};
    use std::{thread, time::Duration};

    let port_name = "COM4";
    let baud_rate = 115200;
    let data_bits = DataBits::Eight;
    let stop_bits = StopBits::One;
    let parity = Parity::None;
    let flow_control = FlowControl::None;

    let mut i = 0;

    let builder = serialport::new(port_name, baud_rate)
        .data_bits(data_bits)
        .stop_bits(stop_bits)
        .parity(parity)
        .flow_control(flow_control);

    let mut ss = Session::new(builder);
    ss.run();

    loop {
        i += 1;
        if i == 2 {
            logger::lgprint("send", "");
            ss.send("ping!");
        } else if i == 3 {
        } else if i == 5 {
            logger::lgprint("send", "");
            ss.send("ping!");
        } else if i == 10 {
            ss.close_thread();
        } else if i == 15 {
            logger::lgprint("restart", "");
            ss.run();
        } else if i == 17 {
            ss.send("ping!");
        }
        println!("{:?}", i);
        thread::sleep(Duration::from_millis(500));
    }
}

#[cfg(not(windows))]
fn main() {}
